package com.qn.visitor.controlle;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.qn.common.base.BaseControlle;
import com.qn.common.base.model.ResponseMode;
import com.qn.visitor.util.VisitorUtil;
import com.qn.visitor.entity.VisitorEventRecord;
import com.qn.visitor.model.UserVisitorRequest;
import com.qn.visitor.service.VisitorEventRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */

@Tag(name = "访客-自定义事件")
@SaCheckLogin
@RestController
@RequestMapping("event")
public class EventController extends BaseControlle {
    @DubboReference(version = "1.0.0")
    private VisitorEventRecordService service;
    @Operation(summary = "用户自定义事件写入")
    @SaIgnore
    @GetMapping("/add/")
    public ResponseMode analys(
            @Parameter(name = "vid", description = "访客记录ID") @RequestParam(required = false) Integer vid,
            @Parameter(name = "eid", description = "自定义事件ID") @RequestParam(required = false) Integer eid,
            HttpServletRequest request) throws Exception {
        //获取数据
        UserVisitorRequest uvrBo = VisitorUtil.getVisitorEvent(request);
        //组装数据
        VisitorEventRecord record=new VisitorEventRecord();
        record.setEId(eid);
        record.setVId(vid);
        record.setPath(uvrBo.getPath());
        record.setHost(uvrBo.getHost());
        record.setCkf(uvrBo.getCkf());
        record.setIp4(uvrBo.getClientIp());
        record.setH2(uvrBo.getH2());
        record.setJa4(uvrBo.getJa4());
        service.add(record);
        return success();
    }
}